package com.ht.data;

import com.ht.em.ResultEnum;

import java.io.Serializable;

public class Result<T> implements Serializable {
    private Integer code;
    private String message;
    private T data;
    private Integer pageNumber;

    public static Result OK(){
        Result result = new Result();
        result.setCode(ResultCode.SUCCESS_CODE); //自定义成功返回码
        result.setMessage(ResultCode.SUCCESS_MESSAGE);
        return result;
    }

    public static Result ERROR(){
        Result result = new Result();
        result.setCode(ResultCode.ERROR_CODE); //自定义成功返回码
        result.setMessage(ResultCode.ERROR_MESSAGE);
        return result;
    }

    public static Result response(ResultEnum resultEnum){
        Result result = new Result();
        result.setCode(resultEnum.getStatus()); //自定义成功返回码
        result.setMessage(resultEnum.getStatusInfo());
        return result;
    }

    public static Result fallback() {
        Result result = new Result();
        result.setCode(ResultEnum.FEIGN_FALLBACK.getStatus());
        result.setMessage(ResultEnum.FEIGN_FALLBACK.getStatusInfo());
        return result;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public Result<T> setData(T data) {
        this.data = data;
        return this;
    }

    public Integer getPageNumber() {
        return pageNumber;
    }

    public Result setPageNumber(Integer pageNumber) {
        this.pageNumber=pageNumber;
        return this;
    }
}
